package com.zh.springcloud.controller;

import com.zh.springcloud.common.Result;
import com.zh.springcloud.entity.Payment;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @Description:
 * @ClassName OrderController
 * @date: 2021.06.09 11:17
 * @Author: zhanghang
 */
@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {
//	private final static String PAYMENT_PATH = "http://localhost:8081";
	// 使用服务名的方式可以访问集群来实现负载均衡
	private final static String PAYMENT_PATH = "http://cloud-provider-payment";

	@Autowired
	private RestTemplate restTemplate;

	@PostMapping("/save")
	@ApiOperation(value = "添加订单")

	public Result<?> savePayment(@RequestBody Payment payment){
		return restTemplate.postForObject(PAYMENT_PATH+"/payment/save",payment,Result.class);
	}

	@GetMapping("/{id}")
	@ApiOperation(value = "获取订单")
	public Result<?> getPaymentById(@PathVariable Long id){
		return restTemplate.getForObject(PAYMENT_PATH+"/payment/"+id,Result.class);
	}

	@GetMapping("/consul")
	@ApiOperation(value = "获取订单")
	public String getPaymentConsule(){
		return restTemplate.getForObject(PAYMENT_PATH+"/payment/consul",String.class);
	}
}
